<%@LANGUAGE="JAVASCRIPT" CODEPAGE="65001"%>
<!--#include file="../connections/connect.asp" -->
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
<%
	var user = Session("user")
	if(user == null){		
		Response.Redirect("../notification.asp")
	}
	else
	{
	var shipAdd = Request.Form("shipAddres")
	var prodID = Request.Form("prodID")
	
	var shipName = Request.Form("shipName")
	var quantity= Request.Form("quantity")
	var price=Request.Form("price")
	var total = quantity*price
	var sql = "Insert into [Order](CustomerID,OrderDate,ShipAddress,[Status],TotalPrice,Quantity,ShippingName) Values('"+user+"',GETDATE(),'"+shipAdd+"',0,'"+total+"','"+quantity+"','"+shipName+"')"	
	var list = conn.Execute(sql)	
	
	
	//Select OrderIDlastest
	
	var sqll = "Select MAX(OrderID) as kq from [Order]"
	var last = conn.Execute(sqll)
	var orderLast = parseInt(last.Fields("kq"))

	//Insert into OrderDetails
	
	var sqldetail = "Insert Into OrderDetail(OrderID,ProductID,Quantity,Price) Values ('"+orderLast+"','"+prodID+"','"+quantity+"','"+price+"')"
	var detail = conn.Execute(sqldetail)
	
	Response.Redirect("../BuySuccess.asp")
	}
				
%>
</body>
</html>
